import Vue from 'vue';
import Vuex from 'vuex'; 
// import * as custom from './../utils/util'
const CryptoJS = require('crypto-js');
// 加密密钥（16 位）
const secretKey = '123456321456';

// 使用 AES 算法进行加密
// const ciphertext = CryptoJS.AES.encrypt(plaintext, secretKey).toString();

// console.log('Ciphertext:', ciphertext);


Vue.use(Vuex);
// 登录验证
export default new Vuex.Store({
  state: {
    user: '',
    cInfo: '',
    indexToInsert: 5,
    charToInsert: '',
    noticeData: "",
    isRecharge: false,
    isDialog: false,
    userType:1
  },
  mutations: { 
    user(state, user) { 
      // custom.setStoreS("uussffoo",{
      //   user:JSON.stringify(user)
      // })
      window.sessionStorage.setItem("uussffoo", CryptoJS.AES.encrypt(user, secretKey).toString());
      state.user = user;
    }, 
    cInfo(state, cInfo) {
      state.cInfo = cInfo;
    },
    logout(state) {
      state.user = '';
      state.cInfo = '';
      state.noticeData = '';
      window.sessionStorage.removeItem("uussffoo");
    },
    noticeData(state, noticeData) { 
      state.noticeData = noticeData;
    }, 
    isRecharge(state, isRecharge) {
      state.isRecharge = isRecharge;
    },
    isDialog(state, isDialog) {
      state.isDialog = isDialog;
    }
  },
  getters: {
    getUser: state => {
      window.sessionStorage.setItem("uussffoo",CryptoJS.AES.encrypt(state.user, secretKey).toString()); 
      // custom.setStoreS("uussffoo",{
      //   user:JSON.stringify(state.user)
      // })

      return state.user
    },
    getcInfo:  state => {
      return state.cInfo
    }, 
    getLoding:  state => {
      return state.isDialog
    },
  },
})